package com.ymttest.database.sqlwapper.sqmarketing;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.sqmarketing.SendUserCoupon;

public class SendUserCouponWrapper {

	SqlManager manager;

	public SendUserCouponWrapper() {
		manager = new SqlManager("sqmarketing");
	}

	@SuppressWarnings("unchecked")
	public SendUserCoupon selectByPrimaryKey(Long id) {

		SendUserCoupon sendUserCoupon = null;

		List<SendUserCoupon> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqmarketing.SendUserCouponMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0)
			sendUserCoupon = result.get(0);

		return sendUserCoupon;
	}
	
	@SuppressWarnings("unchecked")
	public SendUserCoupon selectByMainOrderId(Long mainOrderId) {

		SendUserCoupon sendUserCoupon = null;

		List<SendUserCoupon> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqmarketing.SendUserCouponMapper.selectByMainOrderId",
						mainOrderId);
		manager.commit();

		if (result.size() > 0)
			sendUserCoupon = result.get(0);

		return sendUserCoupon;
	}
	
	@SuppressWarnings("unchecked")
	public SendUserCoupon selectByMainOrderIdAndActivityIdAndCoupon(Long mainOrderId, Long activityId, String coupon) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("main_order_id", mainOrderId);
		map.put("activity_id", activityId);
		map.put("coupon_batch_id", coupon);

		SendUserCoupon sendUserCoupon = null;

		List<SendUserCoupon> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqmarketing.SendUserCouponMapper.selectByMainOrderIdAndActivityIdAndCoupon",
						map);
		manager.commit();

		if (result.size() > 0)
			sendUserCoupon = result.get(0);

		return sendUserCoupon;
	}
	
	public static void main(String[] args) {
		
		SendUserCouponWrapper wrapper = new SendUserCouponWrapper();

		System.out.println(wrapper.selectByMainOrderId(21121608699L));
	}
}
